package com.xgry.bpm.api.base.beeper.service.impl;

import com.xgry.bpm.api.base.beeper.entity.Beeper;
import com.xgry.bpm.api.base.beeper.mapper.BeeperMapper;
import com.xgry.bpm.api.base.beeper.service.BeeperService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.apache.http.HttpStatus;

import java.util.List;

/**
* <p>
    * Beeper服务实现类
    * </p>
*
* @author adrian
* @since 2020-07-08
*/
@Service
public class BeeperServiceImpl extends ServiceImpl<BeeperMapper, Beeper>implements BeeperService {

    @Override
    public int deleteById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        return baseMapper.deleteById(id);
    }

    @Override
    public Beeper selectById(String id){
        if(StringUtils.isEmpty(id)){
            throw new IllegalArgumentException(String.valueOf(HttpStatus.SC_METHOD_FAILURE));
        }
        Beeper data=baseMapper.selectById(id);
        return data;
    }

    @Override
    public List<Beeper>selectAll(Beeper record){
        QueryWrapper<Beeper>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        List<Beeper>list=baseMapper.selectList(queryWrapper);
        return list;
    }

    @Override
    public IPage<Beeper>selectPage(IPage<Beeper> page , Beeper record){
        // 查询条件
        QueryWrapper<Beeper>queryWrapper=new QueryWrapper<>();
        queryWrapper.setEntity(record);
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public IPage<Beeper>getPage(IPage<Beeper>page,QueryWrapper<Beeper>queryWrapper){
        return baseMapper.selectPage(page,queryWrapper);
    }

    @Override
    public List<Beeper> findListByPublish(String publish) {
        return baseMapper.selectList(new QueryWrapper<Beeper>(){{
            this.eq("publish",publish);
        }});
    }
}